<?php
namespace Home\Controller;
header('Access-Control-Allow-Origin:*');
class LoginController extends CommonController {
    // 后台登录
    public function index(){
        $this->display("Index/adminlogin");
    }
    //主播登录接口
    public function admin_login()
    {
        if (IS_POST){
            $heard_adminname = I('post.heard_adminname');
            $password = I('post.password');
            if(empty($heard_adminname)||empty($password)){
                $this->error('参数错误',"",1);
            }
            if(M('admin')->where(array('heard_adminname'=>$heard_adminname))->find() == FALSE){
                $this->error('无效帐号',"",1);
            }
            $password = md5($password);
            $member = M('admin')->where(array('heard_adminname'=>$heard_adminname,'password'=>$password))->find();
            if($member){
                cookie('heardadminData',urlsafe_b64encode($member['heard_admin_id']),18000);
                cookie('heardadminPower',$member['powerlist'],18000);
                cookie('founder',$member['founder'],18000);
                cookie('sex',$member['sex'],18000);
                // RedisSet('heardadminData',urlsafe_b64encode($member['password']),18000);
                $this->adminlog("登录成功".get_client_ip());
                $this->success('登录成功',"/Home/Index",1);
            }else{
                $this->error('密码错误',"",1);
            }
        }else{
            $this->error('登录失败',"",1);
        }
    }

    //退出登录
    public function outLogin(){
        cookie(null);
        cookie('heardadminData',null);
        cookie('heardadminPower',null);
        cookie('founder',null);
        // RedisDelete('heardadminData'); // 删除name
        $this->redirect('/Home/Login');
    }

    public function Apiarticles(){
        $this->ApiSuccess('ok',C('articles'));
    }
    public function articles(){
        exit(json_encode(C('articles')));
    }

}